package com.ourteam.system.api;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.system.dao.ISysDomainDAO;
import com.ourteam.system.dao.SysDomainDAOQueryBean;
import com.ourteam.system.domain.ApplicationDomain;

public class SystemDomainSearchModel extends
		AbstractSearchModel<SysDomainDAOQueryBean> {

	private String name;

	private String code;
	
	private String[] status;

	@Override
	public String getMappedDAOField(String aProperty) {
		return ApplicationDomain.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(SysDomainDAOQueryBean queryBean)
			throws Exception {

		SysDomainDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (StringUtils.isNotBlank(name)) {
			criteria.andDomainNameLike(name);
		}

		if (StringUtils.isNotBlank(code)) {
			criteria.andDomainCodeLike(code);
		}
		
		if (ArrayUtils.isNotEmpty(status)) {
			criteria.andStatusIn(status);
		}

		queryBean.setSortProperty(ISysDomainDAO.SortIndex, true);

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}
	
}
